package com.dyava.commons.validate;

public class ValidateString extends Validate<String,ValidateString> {
	
	public ValidateString(String value,String name) {
		this.value = value;
		this.name = name;
	}

	
	public ValidateString isNotBlank(){
		if (checkNull()) return this;
		if(!value.trim().equals("")){
			return this;
		}
		throw new ValidateFastException(name+"不能为空");
	}
	
	public ValidateString isNotEmpty(){
		if (checkNull()) return this;
		if(!value.equals("")){
			return this;
		}
		throw new ValidateFastException(name+"不能为空");
	}
	

	public ValidateString lenEq(int len){
		if (checkNull()) return this;
		if(this.value.length()==len){
			return this;
		}
		throw new ValidateFastException(name+"长度必须等于"+len);
	}
	
	public ValidateString lenGt(int len){
		if (checkNull()) return this;
		if(this.value.length()>len){
			return this;
		}
		throw new ValidateFastException(name+"长度必须大于"+len);
	}
	
	public ValidateString lenLt(int len){
		if (checkNull()) return this;
		if(this.value.length()<len){
			return this;
		}
		throw new ValidateFastException(name+"长度必须小于"+len);
	}
	
	public ValidateString lenGe(int len){
		if (checkNull()) return this;
		if(this.value.length()>=len){
			return this;
		}
		throw new ValidateFastException(name+"长度必须大于等于"+len);
	}
	
	public ValidateString lenLe(int len){
		if (checkNull()) return this;
		if(this.value.length()<=len){
			return this;
		}
		throw new ValidateFastException(name+"长度必须小于等于"+len);
	}

	public ValidateString isInteger(){
		if (checkNull()) return this;
		if(this.value.matches("^[\\d]+$")){
			return this;
		}
		throw new ValidateFastException(name+"必须是整数");
	}

}
